home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / mono / 2.0 / DefaultWsdlHelpGenerator.aspx next >
Encoding:
Text File  |  2007-02-27  |  57.3 KB  |  1,830 lines

  1. <%--
  2. //
  3. // DefaultWsdlHelpGenerator.aspx: 
  4. //
  5. // Author:
  6. //   Lluis Sanchez Gual (lluis@ximian.com)
  7. //
  8. // (C) 2003 Ximian, Inc.  http://www.ximian.com
  9. //
  10. --%>
  11.  
  12. <%@ Import Namespace="System.Collections" %>
  13. <%@ Import Namespace="System.IO" %>
  14. <%@ Import Namespace="System.Xml.Serialization" %>
  15. <%@ Import Namespace="System.Xml" %>
  16. <%@ Import Namespace="System.Xml.Schema" %>
  17. <%@ Import Namespace="System.Web.Services" %>
  18. <%@ Import Namespace="System.Web.Services.Description" %>
  19. <%@ Import Namespace="System" %>
  20. <%@ Import Namespace="System.Net" %>
  21. <%@ Import Namespace="System.Globalization" %>
  22. <%@ Import Namespace="System.Resources" %>
  23. <%@ Import Namespace="System.Diagnostics" %>
  24. <%@ Import Namespace="System.CodeDom" %>
  25. <%@ Import Namespace="System.CodeDom.Compiler" %>
  26. <%@ Import Namespace="Microsoft.CSharp" %>
  27. <%@ Import Namespace="Microsoft.VisualBasic" %>
  28. <%@ Import Namespace="System.Text.RegularExpressions" %>
  29. <%@ Import Namespace="System.Security.Cryptography.X509Certificates" %>
  30. <%@ Assembly name="System.Web.Services" %>
  31. <%@ Page debug="true" %>
  32.  
  33. <html>
  34. <script language="C#" runat="server">
  35.  
  36. ServiceDescriptionCollection descriptions;
  37. XmlSchemas schemas;
  38.  
  39. string WebServiceName;
  40. string WebServiceDescription;
  41. string PageName;
  42.  
  43. string DefaultBinding;
  44. ArrayList ServiceProtocols;
  45.  
  46. string CurrentOperationName;
  47. string CurrentOperationBinding;
  48. string OperationDocumentation;
  49. string CurrentOperationFormat;
  50. bool CurrentOperationSupportsTest;
  51. ArrayList InParams;
  52. ArrayList OutParams;
  53. string CurrentOperationProtocols;
  54. int CodeTextColumns = 95;
  55. BasicProfileViolationCollection ProfileViolations;
  56.  
  57. void Page_Load(object sender, EventArgs e)
  58. {
  59.     descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
  60.     schemas = (XmlSchemas) Context.Items["schemas"];
  61.  
  62.     ServiceDescription desc = descriptions [0];
  63.     if (schemas.Count == 0) schemas = desc.Types.Schemas;
  64.     
  65.     Service service = desc.Services[0];
  66.     WebServiceName = service.Name;
  67.     if (desc.Bindings.Count == 0)
  68.         return;
  69.     
  70.     DefaultBinding = desc.Bindings[0].Name;
  71.     WebServiceDescription = service.Documentation;
  72.     if (WebServiceDescription == "" || WebServiceDescription == null)
  73.         WebServiceDescription = "Description has not been provided";
  74.     ServiceProtocols = FindServiceProtocols (null);
  75.     
  76.     CurrentOperationName = Request.QueryString["op"];
  77.     CurrentOperationBinding = Request.QueryString["bnd"];
  78.     if (CurrentOperationName != null) BuildOperationInfo ();
  79.  
  80.     PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
  81.  
  82.     ArrayList list = new ArrayList ();
  83.     foreach (ServiceDescription sd in descriptions) {
  84.         foreach (Binding bin in sd.Bindings)
  85.             if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
  86.     }
  87.  
  88.     BindingsRepeater.DataSource = list;
  89.     Page.DataBind();
  90.     
  91.     ProfileViolations = new BasicProfileViolationCollection ();
  92.     WebServicesInteroperability.CheckConformance (WsiProfiles.BasicProfile1_1, descriptions, ProfileViolations);
  93. }
  94.  
  95. void BuildOperationInfo ()
  96. {
  97.     InParams = new ArrayList ();
  98.     OutParams = new ArrayList ();
  99.     
  100.     Port port = FindPort (CurrentOperationBinding, null);
  101.     Binding binding = descriptions.GetBinding (port.Binding);
  102.     
  103.     PortType portType = descriptions.GetPortType (binding.Type);
  104.     Operation oper = FindOperation (portType, CurrentOperationName);
  105.     
  106.     OperationDocumentation = oper.Documentation;
  107.     if (OperationDocumentation == null || OperationDocumentation == "")
  108.         OperationDocumentation = "No additional remarks";
  109.     
  110.     foreach (OperationMessage opm in oper.Messages)
  111.     {
  112.         if (opm is OperationInput)
  113.             BuildParameters (InParams, opm);
  114.         else if (opm is OperationOutput)
  115.             BuildParameters (OutParams, opm);
  116.     }
  117.     
  118.     // Protocols supported by the operation
  119.     CurrentOperationProtocols = "";
  120.     ArrayList prots = FindServiceProtocols (CurrentOperationName);
  121.     for (int n=0; n<prots.Count; n++) {
  122.         if (n != 0) CurrentOperationProtocols += ", ";
  123.         CurrentOperationProtocols += (string) prots[n];
  124.     }
  125.     
  126.     CurrentOperationSupportsTest = prots.Contains ("HttpGet") || prots.Contains ("HttpPost");
  127.  
  128.     // Operation format
  129.     OperationBinding obin = FindOperation (binding, CurrentOperationName);
  130.     if (obin != null)
  131.         CurrentOperationFormat = GetOperationFormat (obin);
  132.  
  133.     InputParamsRepeater.DataSource = InParams;
  134.     InputFormParamsRepeater.DataSource = InParams;
  135.     OutputParamsRepeater.DataSource = OutParams;
  136. }
  137.  
  138. void BuildParameters (ArrayList list, OperationMessage opm)
  139. {
  140.     Message msg = descriptions.GetMessage (opm.Message);
  141.     if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
  142.     {
  143.         MessagePart part = msg.Parts[0];
  144.         XmlSchemaComplexType ctype;
  145.         if (part.Element == XmlQualifiedName.Empty)
  146.         {
  147.             ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
  148.         }
  149.         else
  150.         {
  151.             XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  152.             ctype = (XmlSchemaComplexType) elem.SchemaType;
  153.         }
  154.         XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
  155.         if (seq == null) return;
  156.         
  157.         foreach (XmlSchemaObject ob in seq.Items)
  158.         {
  159.             Parameter p = new Parameter();
  160.             p.Description = "No additional remarks";
  161.             
  162.             if (ob is XmlSchemaElement)
  163.             {
  164.                 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
  165.                 p.Name = selem.Name;
  166.                 p.Type = selem.SchemaTypeName.Name;
  167.             }
  168.             else
  169.             {
  170.                 p.Name = "Unknown";
  171.                 p.Type = "Unknown";
  172.             }
  173.             list.Add (p);
  174.         }
  175.     }
  176.     else
  177.     {
  178.         foreach (MessagePart part in msg.Parts)
  179.         {
  180.             Parameter p = new Parameter ();
  181.             p.Description = "No additional remarks";
  182.             p.Name = part.Name;
  183.             if (part.Element == XmlQualifiedName.Empty)
  184.                 p.Type = part.Type.Name;
  185.             else
  186.             {
  187.                 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  188.                 p.Type = elem.SchemaTypeName.Name;
  189.             }
  190.             list.Add (p);
  191.         }
  192.     }
  193. }
  194.  
  195. string GetOperationFormat (OperationBinding obin)
  196. {
  197.     string format = "";
  198.     SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  199.     if (sob != null) {
  200.         format = sob.Style.ToString ();
  201.         SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  202.         if (sbb != null)
  203.             format += " / " + sbb.Use;
  204.     }
  205.     return format;
  206. }
  207.  
  208. XmlSchemaElement GetRefElement (XmlSchemaElement elem)
  209. {
  210.     if (!elem.RefName.IsEmpty)
  211.         return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  212.     else
  213.         return elem;
  214. }
  215.  
  216. ArrayList FindServiceProtocols(string operName)
  217. {
  218.     ArrayList table = new ArrayList ();
  219.     Service service = descriptions[0].Services[0];
  220.     foreach (Port port in service.Ports)
  221.     {
  222.         string prot = null;
  223.         Binding bin = descriptions.GetBinding (port.Binding);
  224.         if (bin.Extensions.Find (typeof(SoapBinding)) != null)
  225.             prot = "Soap";
  226.         else 
  227.         {
  228.             HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
  229.             if (hb != null && hb.Verb == "POST") prot = "HttpPost";
  230.             else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
  231.         }
  232.         
  233.         if (prot != null && operName != null)
  234.         {
  235.             if (FindOperation (bin, operName) == null)
  236.                 prot = null;
  237.         }
  238.  
  239.         if (prot != null && !table.Contains (prot))
  240.             table.Add (prot);
  241.     }
  242.     return table;
  243. }
  244.  
  245. Port FindPort (string portName, string protocol)
  246. {
  247.     Service service = descriptions[0].Services[0];
  248.     foreach (Port port in service.Ports)
  249.     {
  250.         if (portName == null)
  251.         {
  252.             Binding binding = descriptions.GetBinding (port.Binding);
  253.             if (GetProtocol (binding) == protocol) return port;
  254.         }
  255.         else if (port.Name == portName)
  256.             return port;
  257.     }
  258.     return null;
  259. }
  260.  
  261. string GetProtocol (Binding binding)
  262. {
  263.     if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
  264.     HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
  265.     if (hb == null) return "";
  266.     if (hb.Verb == "POST") return "HttpPost";
  267.     if (hb.Verb == "GET") return "HttpGet";
  268.     return "";
  269. }
  270.  
  271.  
  272. Operation FindOperation (PortType portType, string name)
  273. {
  274.     foreach (Operation oper in portType.Operations) {
  275.         if (oper.Messages.Input.Name != null) {
  276.             if (oper.Messages.Input.Name == name) return oper;
  277.         }
  278.         else
  279.             if (oper.Name == name) return oper;
  280.     }
  281.         
  282.     return null;
  283. }
  284.  
  285. OperationBinding FindOperation (Binding binding, string name)
  286. {
  287.     foreach (OperationBinding oper in binding.Operations) {
  288.         if (oper.Input.Name != null) {
  289.             if (oper.Input.Name == name) return oper;
  290.         }
  291.         else 
  292.             if (oper.Name == name) return oper;
  293.     }
  294.         
  295.     return null;
  296. }
  297.  
  298. string FormatBindingName (string name)
  299. {
  300.     if (name == DefaultBinding) return "Methods";
  301.     else return "Methods for binding<br>" + name;
  302. }
  303.  
  304. string GetOpName (object op)
  305. {
  306.     OperationBinding ob = op as OperationBinding;
  307.     if (ob == null) return "";
  308.     if (ob.Input.Name != null) return ob.Input.Name;
  309.     else return ob.Name;
  310. }
  311.  
  312. bool HasFormResult
  313. {
  314.     get { return Request.QueryString ["ext"] == "testform"; }
  315. }
  316.  
  317. class NoCheckCertificatePolicy : ICertificatePolicy {
  318.     public bool CheckValidationResult (ServicePoint a, X509Certificate b, WebRequest c, int d)
  319.     {
  320.         return true;
  321.     }
  322. }
  323.  
  324. string GetTestResult ()
  325.     if (!HasFormResult) return null;
  326.     
  327.     bool fill = false;
  328.     string qs = "";
  329.     for (int n=0; n<Request.QueryString.Count; n++)
  330.     {
  331.         if (fill) {
  332.             if (qs != "") qs += "&";
  333.             qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
  334.         }
  335.         if (Request.QueryString.GetKey(n) == "ext") fill = true;
  336.     }
  337.         
  338.     string location = null;
  339.     ServiceDescription desc = descriptions [0];
  340.     Service service = desc.Services[0];
  341.     foreach (Port port in service.Ports)
  342.         if (port.Name == CurrentOperationBinding)
  343.         {
  344.             SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
  345.             if (sbi != null)
  346.                 location = sbi.Location;
  347.         }
  348.  
  349.     if (location == null) 
  350.         return "Could not locate web service";
  351.     
  352.     try
  353.     {
  354.         string url = location + "/" + CurrentOperationName;
  355.         Uri uri = new Uri (url);
  356.         HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url + "?" + qs);
  357.         if (url.StartsWith ("https:"))
  358.             ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy ();
  359.         HttpCookieCollection cookies = Request.Cookies;
  360.         int last = cookies.Count;
  361.         if (last > 0) {
  362.             CookieContainer container = new CookieContainer ();
  363.             for (int i = 0; i < last; i++) {
  364.                 HttpCookie hcookie = cookies [i];
  365.                 Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
  366.                 container.Add (uri, cookie);
  367.             }
  368.             ((HttpWebRequest) req).CookieContainer = container;
  369.         }
  370.         WebResponse resp = req.GetResponse();
  371.         StreamReader sr = new StreamReader (resp.GetResponseStream());
  372.         string s = sr.ReadToEnd ();
  373.         sr.Close ();
  374.         return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  375.     }
  376.     catch (Exception ex)
  377.     { 
  378.         string res = "<b style='color:red'>" + ex.Message + "</b>";
  379.         WebException wex = ex as WebException;
  380.         if (wex != null)
  381.         {
  382.             WebResponse resp = wex.Response;
  383.             if (resp != null) {
  384.                 StreamReader sr = new StreamReader (resp.GetResponseStream());
  385.                 string s = sr.ReadToEnd ();
  386.                 sr.Close ();
  387.                 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  388.             }
  389.         }
  390.         return res;
  391.     }
  392. }
  393.  
  394. string GenerateOperationMessages (string protocol, bool generateInput)
  395. {
  396.     if (!IsOperationSupported (protocol)) return "";
  397.     
  398.     Port port;
  399.     if (protocol != "Soap") port = FindPort (null, protocol);
  400.     else port = FindPort (CurrentOperationBinding, null);
  401.     
  402.     Binding binding = descriptions.GetBinding (port.Binding);
  403.     OperationBinding obin = FindOperation (binding, CurrentOperationName);
  404.     PortType portType = descriptions.GetPortType (binding.Type);
  405.     Operation oper = FindOperation (portType, CurrentOperationName);
  406.     
  407.     HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
  408.     string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
  409.     if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
  410.     txt = ColorizeXml (txt);
  411.     txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
  412.     txt = txt.Replace ("!placeholder@","</span>");
  413.     return txt;
  414. }
  415.  
  416. bool IsOperationSupported (string protocol)
  417. {
  418.     if (CurrentPage != "op" || CurrentTab != "msg") return false;
  419.     if (protocol == "Soap") return true;
  420.  
  421.     Port port = FindPort (null, protocol);
  422.     if (port == null) return false;
  423.     Binding binding = descriptions.GetBinding (port.Binding);
  424.     if (binding == null) return false;
  425.     return FindOperation (binding, CurrentOperationName) != null;
  426. }
  427.  
  428. //
  429. // Proxy code generation
  430. //
  431.  
  432. string GetProxyCode ()
  433. {
  434.     CodeNamespace codeNamespace = new CodeNamespace();
  435.     CodeCompileUnit codeUnit = new CodeCompileUnit();
  436.     
  437.     codeUnit.Namespaces.Add (codeNamespace);
  438.  
  439.     ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
  440.     
  441.     foreach (ServiceDescription sd in descriptions)
  442.         importer.AddServiceDescription(sd, null, null);
  443.  
  444.     foreach (XmlSchema sc in schemas)
  445.         importer.Schemas.Add (sc);
  446.  
  447.     importer.Import(codeNamespace, codeUnit);
  448.  
  449.     string langId = Request.QueryString ["lang"];
  450.     if (langId == null || langId == "") langId = "cs";
  451.     CodeDomProvider provider = GetProvider (langId);
  452.     ICodeGenerator generator = provider.CreateGenerator();
  453.     CodeGeneratorOptions options = new CodeGeneratorOptions();
  454.     
  455.     StringWriter sw = new StringWriter ();
  456.     generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
  457.  
  458.     return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
  459. }
  460.  
  461. public string CurrentLanguage
  462. {
  463.     get {
  464.         string langId = Request.QueryString ["lang"];
  465.         if (langId == null || langId == "") langId = "cs";
  466.         return langId;
  467.     }
  468. }
  469.  
  470. public string CurrentProxytName
  471. {
  472.     get {
  473.         string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
  474.         return lan + " Client Proxy";
  475.     }
  476. }
  477.  
  478. private CodeDomProvider GetProvider(string langId)
  479. {
  480.     switch (langId.ToUpper())
  481.     {
  482.         case "CS": return new CSharpCodeProvider();
  483.         case "VB": return new VBCodeProvider();
  484.         default: return null;
  485.     }
  486. }
  487.  
  488. //
  489. // Document generation
  490. //
  491.  
  492. string GenerateDocument ()
  493. {
  494.     StringWriter sw = new StringWriter ();
  495.     
  496.     if (CurrentDocType == "wsdl")
  497.         descriptions [CurrentDocInd].Write (sw);
  498.     else if (CurrentDocType == "schema")
  499.         schemas [CurrentDocInd].Write (sw);
  500.         
  501.     return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
  502. }
  503.  
  504. public string CurrentDocType
  505. {
  506.     get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
  507. }
  508.  
  509. public int CurrentDocInd
  510. {
  511.     get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
  512. }
  513.  
  514. public string CurrentDocumentName
  515. {
  516.     get {
  517.         if (CurrentDocType == "wsdl")
  518.             return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
  519.         else
  520.             return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
  521.     }
  522. }
  523.  
  524. //
  525. // Pages and tabs
  526. //
  527.  
  528. bool firstTab = true;
  529. ArrayList disabledTabs = new ArrayList ();
  530.  
  531. string CurrentTab
  532. {
  533.     get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
  534. }
  535.  
  536. string CurrentPage
  537. {
  538.     get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
  539. }
  540.  
  541. void WriteTabs ()
  542. {
  543.     if (CurrentOperationName != null)
  544.     {
  545.         WriteTab ("main","Overview");
  546.         WriteTab ("test","Test Form");
  547.         WriteTab ("msg","Message Layout");
  548.     }
  549. }
  550.  
  551. void WriteTab (string id, string label)
  552. {
  553.     if (!firstTab) Response.Write(" | ");
  554.     firstTab = false;
  555.     
  556.     string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
  557.     Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
  558.     Response.Write ("<span class='" + cname + "'>" + label + "</span>");
  559.     Response.Write ("</a>");
  560. }
  561.  
  562. string GetTabContext (string pag, string tab)
  563. {
  564.     if (tab == null) tab = CurrentTab;
  565.     if (pag == null) pag = CurrentPage;
  566.     if (pag != CurrentPage) tab = "main";
  567.     return "page=" + pag + "&tab=" + tab + "&"; 
  568. }
  569.  
  570. string GetPageContext (string pag)
  571. {
  572.     if (pag == null) pag = CurrentPage;
  573.     return "page=" + pag + "&"; 
  574. }
  575.  
  576. class Tab
  577. {
  578.     public string Id;
  579.     public string Label;
  580. }
  581.  
  582. //
  583. // Syntax coloring
  584. //
  585.  
  586. static string keywords_cs =
  587.     "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
  588.     "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
  589.     "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
  590.     "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
  591.     "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
  592.     "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
  593.     "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
  594.     "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
  595.     "\\bnamespace\\b|\\bstring\\b)";
  596.  
  597. static string keywords_vb =
  598.     "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
  599.     "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
  600.     "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
  601.     "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
  602.     "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
  603.     "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
  604.     "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
  605.     "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
  606.     "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
  607.     "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
  608.     "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
  609.     "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
  610.     "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
  611.     "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
  612.     "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
  613.     "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
  614.     "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
  615.  
  616. string Colorize (string text, string lang)
  617. {
  618.     if (lang == "xml") return ColorizeXml (text);
  619.     else if (lang == "cs") return ColorizeCs (text);
  620.     else if (lang == "vb") return ColorizeVb (text);
  621.     else return text;
  622. }
  623.  
  624. string ColorizeXml (string text)
  625. {
  626.     text = text.Replace (" ", " ");
  627.     Regex re = new Regex ("\r\n|\r|\n");
  628.     text = re.Replace (text, "_br_");
  629.     
  630.     re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
  631.     text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
  632.     
  633.     re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
  634.     text = re.Replace (text,"<span style='color:$1'>$2</span>");
  635.  
  636.     re = new Regex ("\"(.*?)\"");
  637.     text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
  638.  
  639.     
  640.     text = text.Replace ("\t", "     ");
  641.     text = text.Replace ("_br_", "<br>");
  642.     return text;
  643. }
  644.  
  645. string ColorizeCs (string text)
  646. {
  647.     text = text.Replace (" ", " ");
  648.  
  649.     text = text.Replace ("<", "<");
  650.     text = text.Replace (">", ">");
  651.  
  652.     Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  653.     text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  654.  
  655.     re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
  656.     text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  657.     
  658.     re = new Regex (keywords_cs);
  659.     text = re.Replace (text,"<span style='color:blue'>$1</span>");
  660.     
  661.     text = text.Replace ("\t","     ");
  662.     text = text.Replace ("\n","<br/>");
  663.     
  664.     return text;
  665. }
  666.  
  667. string ColorizeVb (string text)
  668. {
  669.     text = text.Replace (" ", " ");
  670.     
  671. /*    Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  672.     text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  673.  
  674.     re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
  675.     text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  676.     
  677.     re = new Regex (keywords_vb);
  678.     text = re.Replace (text,"<span style='color:blue'>$1</span>");
  679. */    
  680.     text = text.Replace ("\t","     ");
  681.     text = text.Replace ("\n","<br/>");
  682.     return text;
  683. }
  684.  
  685. //
  686. // Helper methods and classes
  687. //
  688.  
  689. string GetDataContext ()
  690. {
  691.     return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
  692. }
  693.  
  694. string GetOptionSel (string v1, string v2)
  695. {
  696.     string op = "<option ";
  697.     if (v1 == v2) op += "selected ";
  698.     return op + "value='" + v1 + "'>";
  699. }
  700.  
  701. string WrapText (string text, int maxChars)
  702. {
  703.     text =  text.Replace(" />","/>");
  704.     
  705.     string linspace = null;
  706.     int lincount = 0;
  707.     int breakpos = 0;
  708.     int linstart = 0;
  709.     bool inquotes = false;
  710.     char lastc = ' ';
  711.     string sublineIndent = "";
  712.     System.Text.StringBuilder sb = new System.Text.StringBuilder ();
  713.     for (int n=0; n<text.Length; n++)
  714.     {
  715.         char c = text [n];
  716.         
  717.         if (c=='\r' || c=='\n' || n==text.Length-1)
  718.         {
  719.             sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
  720.             linspace = null;
  721.             lincount = 0;
  722.             linstart = n+1;
  723.             breakpos = linstart;
  724.             sublineIndent = "";
  725.             lastc = c;
  726.             continue;
  727.         }
  728.         
  729.         if (lastc==',' || lastc=='(')
  730.         {
  731.             if (!inquotes) breakpos = n;
  732.         }
  733.         
  734.         if (lincount > maxChars && breakpos >= linstart)
  735.         {
  736.             if (linspace != null)
  737.                 sb.Append (linspace + sublineIndent);
  738.             sb.Append (text.Substring (linstart, breakpos-linstart));
  739.             sb.Append ("\n");
  740.             sublineIndent = "     ";
  741.             lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
  742.             linstart = breakpos;
  743.         }
  744.         
  745.         if (c==' ' || c=='\t')
  746.         {
  747.             if (!inquotes)
  748.                 breakpos = n;
  749.         }
  750.         else if (c=='"')
  751.         {
  752.             inquotes = !inquotes;
  753.         }
  754.         else 
  755.             if (linspace == null) {
  756.                 linspace = text.Substring (linstart, n-linstart);
  757.                 linstart = n;
  758.             }
  759.  
  760.         lincount++;
  761.         lastc = c;
  762.     }
  763.     return sb.ToString ();
  764. }
  765.  
  766. class Parameter
  767. {
  768.     string name;
  769.     string type;
  770.     string description;
  771.  
  772.     public string Name { get { return name; } set { name = value; } }
  773.     public string Type { get { return type; } set { type = value; } }
  774.     public string Description { get { return description; } set { description = value; } }
  775. }
  776.  
  777. public class HtmlSampleGenerator: SampleGenerator
  778. {
  779.     public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
  780.     : base (services, schemas)
  781.     {
  782.     }
  783.         
  784.     protected override string GetLiteral (string s)
  785.     {
  786.         return "@placeholder!" + s + "!placeholder@";
  787.     }
  788. }
  789.  
  790.  
  791.     public class SampleGenerator
  792.     {
  793.         protected ServiceDescriptionCollection descriptions;
  794.         protected XmlSchemas schemas;
  795.         XmlSchemaElement anyElement;
  796.         ArrayList queue;
  797.         SoapBindingUse currentUse;
  798.         XmlDocument document = new XmlDocument ();
  799.         
  800.         static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
  801.         static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
  802.         static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
  803.         const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
  804.         const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
  805.         const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
  806.         
  807.         class EncodedType
  808.         {
  809.             public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
  810.             public string Namespace;
  811.             public XmlSchemaElement Element;
  812.         }
  813.  
  814.         public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
  815.         {
  816.             descriptions = services;
  817.             this.schemas = schemas;
  818.             queue = new ArrayList ();
  819.         }
  820.         
  821.         public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
  822.         {
  823.             OperationMessage msg = null;
  824.             foreach (OperationMessage opm in oper.Messages)
  825.             {
  826.                 if (opm is OperationInput && generateInput) msg = opm;
  827.                 else if (opm is OperationOutput && !generateInput) msg = opm;
  828.             }
  829.             if (msg == null) return null;
  830.             
  831.             switch (protocol) {
  832.                 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
  833.                 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
  834.                 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
  835.             }
  836.             return "Unknown protocol";
  837.         }
  838.         
  839.         public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  840.         {
  841.             string req = "";
  842.             
  843.             if (msg is OperationInput)
  844.             {
  845.                 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
  846.                 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  847.                 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
  848.                 req += "SOAPAction: " + sob.SoapAction + "\n";
  849.                 req += "Content-Type: text/xml; charset=utf-8\n";
  850.                 req += "Content-Length: " + GetLiteral ("string") + "\n";
  851.                 req += "Host: " + GetLiteral ("string") + "\n\n";
  852.             }
  853.             else
  854.             {
  855.                 req += "HTTP/1.0 200 OK\n";
  856.                 req += "Content-Type: text/xml; charset=utf-8\n";
  857.                 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
  858.             }
  859.             
  860.             req += GenerateSoapMessage (obin, oper, msg);
  861.             return req;
  862.         }
  863.         
  864.         public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  865.         {
  866.             string req = "";
  867.             
  868.             if (msg is OperationInput)
  869.             {
  870.                 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
  871.                 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
  872.                 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
  873.                 req += "GET " + location + "\n";
  874.                 req += "Host: " + GetLiteral ("string");
  875.             }
  876.             else
  877.             {
  878.                 req += "HTTP/1.0 200 OK\n";
  879.                 req += "Content-Type: text/xml; charset=utf-8\n";
  880.                 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
  881.             
  882.                 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
  883.                 if (mxb == null) return req;
  884.                 
  885.                 Message message = descriptions.GetMessage (msg.Message);
  886.                 XmlQualifiedName ename = null;
  887.                 foreach (MessagePart part in message.Parts)
  888.                     if (part.Name == mxb.Part) ename = part.Element;
  889.                     
  890.                 if (ename == null) return req + GetLiteral("string");
  891.                 
  892.                 StringWriter sw = new StringWriter ();
  893.                 XmlTextWriter xtw = new XmlTextWriter (sw);
  894.                 xtw.Formatting = Formatting.Indented;
  895.                 currentUse = SoapBindingUse.Literal;
  896.                 WriteRootElementSample (xtw, ename);
  897.                 xtw.Close ();
  898.                 req += sw.ToString ();
  899.             }
  900.             
  901.             return req;
  902.         }
  903.         
  904.         public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  905.         {
  906.             string req = "";
  907.             
  908.             if (msg is OperationInput)
  909.             {
  910.                 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
  911.                 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
  912.                 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
  913.                 req += "POST " + location + "\n";
  914.                 req += "Content-Type: application/x-www-form-urlencoded\n";
  915.                 req += "Content-Length: " + GetLiteral ("string") + "\n";
  916.                 req += "Host: " + GetLiteral ("string") + "\n\n";
  917.                 req += BuildQueryString (msg);
  918.             }
  919.             else return GenerateHttpGetMessage (port, obin, oper, msg);
  920.             
  921.             return req;
  922.         }
  923.         
  924.         string BuildQueryString (OperationMessage opm)
  925.         {
  926.             string s = "";
  927.             Message msg = descriptions.GetMessage (opm.Message);
  928.             foreach (MessagePart part in msg.Parts)
  929.             {
  930.                 if (s.Length != 0) s += "&";
  931.                 s += part.Name + "=" + GetLiteral (part.Type.Name);
  932.             }
  933.             return s;
  934.         }
  935.         
  936.         public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
  937.         {
  938.             SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  939.             SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
  940.             
  941.             MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
  942.             SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  943.             SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
  944.             
  945.             StringWriter sw = new StringWriter ();
  946.             XmlTextWriter xtw = new XmlTextWriter (sw);
  947.             xtw.Formatting = Formatting.Indented;
  948.             
  949.             xtw.WriteStartDocument ();
  950.             xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
  951.             xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
  952.             xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
  953.             
  954.             if (bodyUse == SoapBindingUse.Encoded) 
  955.             {
  956.                 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
  957.                 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
  958.             }
  959.  
  960.             // Serialize headers
  961.             
  962.             bool writtenHeader = false;
  963.             foreach (object ob in msgbin.Extensions)
  964.             {
  965.                 SoapHeaderBinding hb = ob as SoapHeaderBinding;
  966.                 if (hb == null) continue;
  967.                 
  968.                 if (!writtenHeader) {
  969.                     xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
  970.                     writtenHeader = true;
  971.                 }
  972.                 
  973.                 WriteHeader (xtw, hb);
  974.             }
  975.             
  976.             if (writtenHeader)
  977.                 xtw.WriteEndElement ();
  978.  
  979.             // Serialize body
  980.             xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
  981.             
  982.             currentUse = bodyUse;
  983.             WriteBody (xtw, oper, msg, sbb, style);
  984.             
  985.             xtw.WriteEndElement ();
  986.             xtw.WriteEndElement ();
  987.             xtw.Close ();
  988.             return sw.ToString ();
  989.         }
  990.         
  991.         void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
  992.         {
  993.             Message msg = descriptions.GetMessage (header.Message);
  994.             if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
  995.             MessagePart part = msg.Parts [header.Part];
  996.             if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
  997.  
  998.             currentUse = header.Use;
  999.             
  1000.             if (currentUse == SoapBindingUse.Literal)
  1001.                 WriteRootElementSample (xtw, part.Element);
  1002.             else
  1003.                 WriteTypeSample (xtw, part.Type);
  1004.         }
  1005.         
  1006.         void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
  1007.         {
  1008.             Message msg = descriptions.GetMessage (opm.Message);
  1009.             if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
  1010.             {
  1011.                 MessagePart part = msg.Parts[0];
  1012.                 if (part.Element == XmlQualifiedName.Empty)
  1013.                     WriteTypeSample (xtw, part.Type);
  1014.                 else
  1015.                     WriteRootElementSample (xtw, part.Element);
  1016.             }
  1017.             else
  1018.             {
  1019.                 string elemName = oper.Name;
  1020.                 string ns = "";
  1021.                 if (opm is OperationOutput) elemName += "Response";
  1022.                 
  1023.                 if (style == SoapBindingStyle.Rpc) {
  1024.                     xtw.WriteStartElement (elemName, sbb.Namespace);
  1025.                     ns = sbb.Namespace;
  1026.                 }
  1027.                     
  1028.                 foreach (MessagePart part in msg.Parts)
  1029.                 {
  1030.                     if (part.Element == XmlQualifiedName.Empty)
  1031.                     {
  1032.                         XmlSchemaElement elem = new XmlSchemaElement ();
  1033.                         elem.SchemaTypeName = part.Type;
  1034.                         elem.Name = part.Name;
  1035.                         WriteElementSample (xtw, ns, elem);
  1036.                     }
  1037.                     else
  1038.                         WriteRootElementSample (xtw, part.Element);
  1039.                 }
  1040.                 
  1041.                 if (style == SoapBindingStyle.Rpc)
  1042.                     xtw.WriteEndElement ();
  1043.             }
  1044.             WriteQueuedTypeSamples (xtw);
  1045.         }
  1046.         
  1047.         void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
  1048.         {
  1049.             XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
  1050.             if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
  1051.             WriteElementSample (xtw, qname.Namespace, elem);
  1052.         }
  1053.         
  1054.         void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
  1055.         {
  1056.             bool sharedAnnType = false;
  1057.             XmlQualifiedName root;
  1058.             
  1059.             if (!elem.RefName.IsEmpty) {
  1060.                 XmlSchemaElement refElem = FindRefElement (elem);
  1061.                 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
  1062.                 root = elem.RefName;
  1063.                 elem = refElem;
  1064.                 sharedAnnType = true;
  1065.             }
  1066.             else
  1067.                 root = new XmlQualifiedName (elem.Name, ns);
  1068.             
  1069.             if (!elem.SchemaTypeName.IsEmpty)
  1070.             {
  1071.                 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
  1072.                 if (st != null) 
  1073.                     WriteComplexTypeSample (xtw, st, root);
  1074.                 else
  1075.                 {
  1076.                     xtw.WriteStartElement (root.Name, root.Namespace);
  1077.                     if (currentUse == SoapBindingUse.Encoded) 
  1078.                         xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
  1079.                     xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
  1080.                     xtw.WriteEndElement ();
  1081.                 }
  1082.             }
  1083.             else if (elem.SchemaType == null)
  1084.             {
  1085.                 xtw.WriteStartElement ("any");
  1086.                 xtw.WriteEndElement ();
  1087.             }
  1088.             else
  1089.                 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
  1090.         }
  1091.         
  1092.         void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
  1093.         {
  1094.             XmlSchemaComplexType ctype = FindComplexTyype (qname);
  1095.             if (ctype != null) {
  1096.                 WriteComplexTypeSample (xtw, ctype, qname);
  1097.                 return;
  1098.             }
  1099.             
  1100.             XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
  1101.             if (stype != null) {
  1102.                 WriteSimpleTypeSample (xtw, stype);
  1103.                 return;
  1104.             }
  1105.             
  1106.             xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
  1107.             throw new InvalidOperationException ("Type not found: " + qname);
  1108.         }
  1109.         
  1110.         void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
  1111.         {
  1112.             WriteComplexTypeSample (xtw, stype, rootName, -1);
  1113.         }
  1114.         
  1115.         void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
  1116.         {
  1117.             string ns = rootName.Namespace;
  1118.             
  1119.             if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
  1120.             
  1121.             if (currentUse == SoapBindingUse.Encoded) {
  1122.                 string pref = xtw.LookupPrefix (rootName.Namespace);
  1123.                 if (pref == null) pref = "q1";
  1124.                 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
  1125.                 ns = "";
  1126.             }
  1127.             else
  1128.                 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
  1129.             
  1130.             if (id != -1)
  1131.             {
  1132.                 xtw.WriteAttributeString ("id", "id" + id);
  1133.                 if (rootName != arrayType)
  1134.                     xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
  1135.             }
  1136.             
  1137.             WriteComplexTypeAttributes (xtw, stype);
  1138.             WriteComplexTypeElements (xtw, ns, stype);
  1139.             
  1140.             xtw.WriteEndElement ();
  1141.         }
  1142.         
  1143.         void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
  1144.         {
  1145.             WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
  1146.         }
  1147.         
  1148.         void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
  1149.         {
  1150.             if (stype.Particle != null)
  1151.                 WriteParticleComplexContent (xtw, ns, stype.Particle);
  1152.             else
  1153.             {
  1154.                 if (stype.ContentModel is XmlSchemaSimpleContent)
  1155.                     WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
  1156.                 else if (stype.ContentModel is XmlSchemaComplexContent)
  1157.                     WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
  1158.             }
  1159.         }
  1160.  
  1161.         void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
  1162.         {
  1163.             foreach (XmlSchemaObject at in atts)
  1164.             {
  1165.                 if (at is XmlSchemaAttribute)
  1166.                 {
  1167.                     string ns;
  1168.                     XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
  1169.                     XmlSchemaAttribute refAttr = attr;
  1170.                     
  1171.                     // refAttr.Form; TODO
  1172.                     
  1173.                     if (!attr.RefName.IsEmpty) {
  1174.                         refAttr = FindRefAttribute (attr.RefName);
  1175.                         if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
  1176.                     }
  1177.                     
  1178.                     string val;
  1179.                     if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
  1180.                     else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
  1181.                     
  1182.                     xtw.WriteAttributeString (refAttr.Name, val);
  1183.                 }
  1184.                 else if (at is XmlSchemaAttributeGroupRef)
  1185.                 {
  1186.                     XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
  1187.                     XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
  1188.                     WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
  1189.                 }
  1190.             }
  1191.             
  1192.             if (anyat != null)
  1193.                 xtw.WriteAttributeString ("custom-attribute","value");
  1194.         }
  1195.         
  1196.         void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
  1197.         {
  1198.             WriteParticleContent (xtw, ns, particle, false);
  1199.         }
  1200.         
  1201.         void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
  1202.         {
  1203.             if (particle is XmlSchemaGroupRef)
  1204.                 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
  1205.  
  1206.             if (particle.MaxOccurs > 1) multiValue = true;
  1207.             
  1208.             if (particle is XmlSchemaSequence) {
  1209.                 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
  1210.             }
  1211.             else if (particle is XmlSchemaChoice) {
  1212.                 if (((XmlSchemaChoice)particle).Items.Count == 1)
  1213.                     WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
  1214.                 else
  1215.                     WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
  1216.             }
  1217.             else if (particle is XmlSchemaAll) {
  1218.                 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
  1219.             }
  1220.         }
  1221.  
  1222.         void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
  1223.         {
  1224.             foreach (XmlSchemaObject item in items)
  1225.                 WriteContentItem (xtw, ns, item, multiValue);
  1226.         }
  1227.         
  1228.         void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
  1229.         {
  1230.             if (item is XmlSchemaGroupRef)
  1231.                 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
  1232.                     
  1233.             if (item is XmlSchemaElement)
  1234.             {
  1235.                 XmlSchemaElement elem = (XmlSchemaElement) item;
  1236.                 XmlSchemaElement refElem;
  1237.                 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
  1238.                 else refElem = elem;
  1239.  
  1240.                 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
  1241.                 for (int n=0; n<num; n++)
  1242.                 {
  1243.                     if (currentUse == SoapBindingUse.Literal)
  1244.                         WriteElementSample (xtw, ns, refElem);
  1245.                     else
  1246.                         WriteRefTypeSample (xtw, ns, refElem);
  1247.                 }
  1248.             }
  1249.             else if (item is XmlSchemaAny)
  1250.             {
  1251.                 xtw.WriteString (GetLiteral ("xml"));
  1252.             }
  1253.             else if (item is XmlSchemaParticle) {
  1254.                 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
  1255.             }
  1256.         }
  1257.         
  1258.         void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
  1259.         {
  1260.             foreach (XmlSchemaObject item in choice.Items)
  1261.                 WriteContentItem (xtw, ns, item, multiValue);
  1262.         }
  1263.  
  1264.         void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
  1265.         {
  1266.             XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
  1267.             if (ext != null)
  1268.                 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
  1269.                 
  1270.             XmlQualifiedName qname = GetContentBaseType (content.Content);
  1271.             xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
  1272.         }
  1273.  
  1274.         string FindBuiltInType (XmlQualifiedName qname)
  1275.         {
  1276.             if (qname.Namespace == XmlSchema.Namespace)
  1277.                 return qname.Name;
  1278.  
  1279.             XmlSchemaComplexType ct = FindComplexTyype (qname);
  1280.             if (ct != null)
  1281.             {
  1282.                 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
  1283.                 if (sc == null) throw new InvalidOperationException ("Invalid schema");
  1284.                 return FindBuiltInType (GetContentBaseType (sc.Content));
  1285.             }
  1286.             
  1287.             XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
  1288.             if (st != null)
  1289.                 return FindBuiltInType (st);
  1290.  
  1291.             throw new InvalidOperationException ("Definition of type " + qname + " not found");
  1292.         }
  1293.  
  1294.         string FindBuiltInType (XmlSchemaSimpleType st)
  1295.         {
  1296.             if (st.Content is XmlSchemaSimpleTypeRestriction) {
  1297.                 return FindBuiltInType (GetContentBaseType (st.Content));
  1298.             }
  1299.             else if (st.Content is XmlSchemaSimpleTypeList) {
  1300.                 string s = FindBuiltInType (GetContentBaseType (st.Content));
  1301.                 return s + " " + s + " ...";
  1302.             }
  1303.             else if (st.Content is XmlSchemaSimpleTypeUnion)
  1304.             {
  1305.                 //Check if all types of the union are equal. If not, then will use anyType.
  1306.                 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
  1307.                 string utype = null;
  1308.  
  1309.                 // Anonymous types are unique
  1310.                 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
  1311.                     return "string";
  1312.  
  1313.                 foreach (XmlQualifiedName mt in uni.MemberTypes)
  1314.                 {
  1315.                     string qn = FindBuiltInType (mt);
  1316.                     if (utype != null && qn != utype) return "string";
  1317.                     else utype = qn;
  1318.                 }
  1319.                 return utype;
  1320.             }
  1321.             else
  1322.                 return "string";
  1323.         }
  1324.         
  1325.  
  1326.         XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
  1327.         {
  1328.             if (ob is XmlSchemaSimpleContentExtension)
  1329.                 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
  1330.             else if (ob is XmlSchemaSimpleContentRestriction)
  1331.                 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
  1332.             else if (ob is XmlSchemaSimpleTypeRestriction)
  1333.                 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
  1334.             else if (ob is XmlSchemaSimpleTypeList)
  1335.                 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
  1336.             else
  1337.                 return null;
  1338.         }
  1339.  
  1340.         void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
  1341.         {
  1342.             XmlQualifiedName qname;
  1343.  
  1344.             XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
  1345.             if (ext != null) qname = ext.BaseTypeName;
  1346.             else {
  1347.                 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
  1348.                 qname = rest.BaseTypeName;
  1349.                 if (qname == arrayType) {
  1350.                     ParseArrayType (rest, out qname);
  1351.                     XmlSchemaElement elem = new XmlSchemaElement ();
  1352.                     elem.Name = "Item";
  1353.                     elem.SchemaTypeName = qname;
  1354.                     
  1355.                     xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
  1356.                     WriteContentItem (xtw, ns, elem, true);
  1357.                     return;
  1358.                 }
  1359.             }
  1360.             
  1361.             // Add base map members to this map
  1362.             XmlSchemaComplexType ctype = FindComplexTyype (qname);
  1363.             WriteComplexTypeAttributes (xtw, ctype);
  1364.             
  1365.             if (ext != null) {
  1366.                 // Add the members of this map
  1367.                 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
  1368.                 if (ext.Particle != null)
  1369.                     WriteParticleComplexContent (xtw, ns, ext.Particle);
  1370.             }
  1371.             
  1372.             WriteComplexTypeElements (xtw, ns, ctype);
  1373.         }
  1374.         
  1375.         void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
  1376.         {
  1377.             XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
  1378.             XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
  1379.             if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
  1380.             
  1381.             XmlAttribute xat = null;
  1382.             foreach (XmlAttribute at in uatts)
  1383.                 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
  1384.                     { xat = at; break; }
  1385.             
  1386.             if (xat == null) 
  1387.                 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
  1388.             
  1389.             string arrayType = xat.Value;
  1390.             string type, ns;
  1391.             int i = arrayType.LastIndexOf (":");
  1392.             if (i == -1) ns = "";
  1393.             else ns = arrayType.Substring (0,i);
  1394.             
  1395.             int j = arrayType.IndexOf ("[", i+1);
  1396.             if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
  1397.             type = arrayType.Substring (i+1);
  1398.             type = type.Substring (0, type.Length-2);
  1399.             
  1400.             qtype = new XmlQualifiedName (type, ns);
  1401.         }
  1402.         
  1403.         XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
  1404.         {
  1405.             foreach (object ob in atts)
  1406.             {
  1407.                 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
  1408.                 if (att != null && att.RefName == arrayTypeRefName) return att;
  1409.                 
  1410.                 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
  1411.                 if (gref != null)
  1412.                 {
  1413.                     XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
  1414.                     att = FindArrayAttribute (grp.Attributes);
  1415.                     if (att != null) return att;
  1416.                 }
  1417.             }
  1418.             return null;
  1419.         }
  1420.         
  1421.         void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
  1422.         {
  1423.             xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
  1424.         }
  1425.         
  1426.         XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
  1427.         {
  1428.             XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
  1429.             return grp.Particle;
  1430.         }
  1431.  
  1432.         XmlSchemaElement FindRefElement (XmlSchemaElement elem)
  1433.         {
  1434.             if (elem.RefName.Namespace == XmlSchema.Namespace)
  1435.             {
  1436.                 if (anyElement != null) return anyElement;
  1437.                 anyElement = new XmlSchemaElement ();
  1438.                 anyElement.Name = "any";
  1439.                 anyElement.SchemaTypeName = anyType;
  1440.                 return anyElement;
  1441.             }
  1442.             return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  1443.         }
  1444.         
  1445.         XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
  1446.         {
  1447.             if (refName.Namespace == XmlSchema.Namespace)
  1448.             {
  1449.                 XmlSchemaAttribute at = new XmlSchemaAttribute ();
  1450.                 at.Name = refName.Name;
  1451.                 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
  1452.                 return at;
  1453.             }
  1454.             return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
  1455.         }
  1456.         
  1457.         void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
  1458.         {
  1459.             if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
  1460.                 WriteElementSample (xtw, ns, elem);
  1461.             else
  1462.             {
  1463.                 xtw.WriteStartElement (elem.Name, ns);
  1464.                 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
  1465.                 xtw.WriteEndElement ();
  1466.                 queue.Add (new EncodedType (ns, elem));
  1467.             }
  1468.         }
  1469.         
  1470.         void WriteQueuedTypeSamples (XmlTextWriter xtw)
  1471.         {
  1472.             for (int n=0; n<queue.Count; n++)
  1473.             {
  1474.                 EncodedType ec = (EncodedType) queue[n];
  1475.                 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
  1476.                 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
  1477.             }
  1478.         }
  1479.         
  1480.         XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
  1481.         {
  1482.             if (qname.Name.IndexOf ("[]") != -1)
  1483.             {
  1484.                 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
  1485.                 stype.ContentModel = new XmlSchemaComplexContent ();
  1486.                 
  1487.                 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
  1488.                 stype.ContentModel.Content = res;
  1489.                 res.BaseTypeName = arrayType;
  1490.                 
  1491.                 XmlSchemaAttribute att = new XmlSchemaAttribute ();
  1492.                 att.RefName = arrayTypeRefName;
  1493.                 res.Attributes.Add (att);
  1494.                 
  1495.                 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
  1496.                 xat.Value = qname.Namespace + ":" + qname.Name;
  1497.                 att.UnhandledAttributes = new XmlAttribute[] {xat};
  1498.                 return stype;
  1499.             }
  1500.                 
  1501.             return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
  1502.         }
  1503.         
  1504.         string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
  1505.         {
  1506.             string pref = xtw.LookupPrefix (qname.Namespace);
  1507.             if (pref != null) return pref + ":" + qname.Name;
  1508.             
  1509.             xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
  1510.             return "q1:" + qname.Name;
  1511.         }
  1512.                 
  1513.         protected virtual string GetLiteral (string s)
  1514.         {
  1515.             return s;
  1516.         }
  1517.  
  1518.         void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
  1519.         {
  1520.             style = SoapBindingStyle.Document;
  1521.             use = SoapBindingUse.Literal;
  1522.             SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  1523.             if (sob != null) {
  1524.                 style = sob.Style;
  1525.                 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  1526.                 if (sbb != null)
  1527.                     use = sbb.Use;
  1528.             }
  1529.         }
  1530.     }
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536. </script>
  1537.  
  1538. <head>
  1539.     <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
  1540.  
  1541.     <title><%=WebServiceName%> Web Service</title>
  1542.     <style type="text/css">
  1543.         BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
  1544.         TABLE { font-size: x-small }
  1545.         .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
  1546.         .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
  1547.         .method { font-size: x-small }
  1548.         .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
  1549.         .label { font-size: small; font-weight:bold; color:darkgray }
  1550.         .paramTable { font-size: x-small }
  1551.         .paramTable TR { background-color: gainsboro }
  1552.         .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
  1553.         .paramFormTable TR { background-color: gainsboro }
  1554.         .paramInput { border: solid 1px gray }
  1555.         .button {border: solid 1px gray }
  1556.         .smallSeparator { height:3px; overflow:hidden }
  1557.         .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver  }
  1558.         .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
  1559.         .code-xml { font-size:10pt; font-family:courier }
  1560.         .code-cs { font-size:10pt; font-family:courier }
  1561.         .code-vb { font-size:10pt; font-family:courier }
  1562.         .tabLabelOn { font-weight:bold }
  1563.         .tabLabelOff {color: darkgray }
  1564.         .literal-placeholder {color: darkblue; font-weight:bold}
  1565.         A:link { color: black; }
  1566.         A:visited { color: black; }
  1567.         A:active { color: black; }
  1568.         A:hover { color: blue }
  1569.     </style>
  1570.     
  1571. <script>
  1572. function clearForm ()
  1573. {
  1574.     document.getElementById("testFormResult").style.display="none";
  1575. }
  1576. </script>
  1577.  
  1578. </head>
  1579.  
  1580. <body>
  1581. <div class="title" style="margin-left:20px">
  1582. <span class="label">Web Service</span><br>
  1583. <%=WebServiceName%>
  1584. </div>
  1585.  
  1586. <!--
  1587.     **********************************************************
  1588.     Left panel
  1589. -->
  1590.  
  1591. <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
  1592. <tr valign="top"><td width="150px" class="panel">
  1593. <div style="width:150px"></div>
  1594. <a class="method" href='<%=PageName%>'>Overview</a><br>
  1595. <div class="smallSeparator"></div>
  1596. <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
  1597. <div class="smallSeparator"></div>
  1598. <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
  1599. <br><br>
  1600.     <asp:repeater id="BindingsRepeater" runat=server>
  1601.         <itemtemplate name="itemtemplate">
  1602.             <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
  1603.             <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
  1604.                 <itemtemplate>
  1605.                     <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
  1606.                     <div class="smallSeparator"></div>
  1607.                 </itemtemplate>
  1608.             </asp:repeater>
  1609.             <br>
  1610.         </itemtemplate>
  1611.     </asp:repeater>
  1612.  
  1613. </td><td class="panel">
  1614.  
  1615. <% if (CurrentPage == "main") {%>
  1616.  
  1617. <!--
  1618.     **********************************************************
  1619.     Web service overview
  1620. -->
  1621.  
  1622.     <p class="label">Web Service Overview</p>
  1623.     <%=WebServiceDescription%>
  1624.     <br/><br/>
  1625.     <% if (ProfileViolations.Count > 0) { %>
  1626.         <p class="label">Basic Profile Conformance</p>
  1627.         This web service does not conform to WS-I Basic Profile v1.1
  1628.     <%
  1629.         Response.Write ("<ul>");
  1630.         foreach (BasicProfileViolation vio in ProfileViolations) {
  1631.             Response.Write ("<li><b>" + vio.NormativeStatement + "</b>: " + vio.Details);
  1632.             Response.Write ("<ul>");
  1633.             foreach (string ele in vio.Elements)
  1634.                 Response.Write ("<li>" + ele + "</li>");
  1635.             Response.Write ("</ul>");
  1636.             Response.Write ("</li>");
  1637.         }
  1638.         Response.Write ("</ul>");
  1639.     }%>
  1640.  
  1641. <%} if (DefaultBinding == null) {%>
  1642. This service does not contain any public web method.
  1643. <%} else if (CurrentPage == "op") {%>
  1644.  
  1645. <!--
  1646.     **********************************************************
  1647.     Operation description
  1648. -->
  1649.  
  1650.     <span class="operationTitle"><%=CurrentOperationName%></span>
  1651.     <br><br>
  1652.     <% WriteTabs (); %>
  1653.     <br><br><br>
  1654.     
  1655.     <% if (CurrentTab == "main") { %>
  1656.         <span class="label">Input Parameters</span>
  1657.         <div class="smallSeparator"></div>
  1658.         <% if (InParams.Count == 0) { %>
  1659.             No input parameters<br>
  1660.         <% } else { %>
  1661.             <table class="paramTable" cellspacing="1" cellpadding="5">
  1662.             <asp:repeater id="InputParamsRepeater" runat=server>
  1663.                 <itemtemplate>
  1664.                     <tr>
  1665.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  1666.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  1667.                     </tr>
  1668.                 </itemtemplate>
  1669.             </asp:repeater>
  1670.             </table>
  1671.         <% } %>
  1672.         <br>
  1673.         
  1674.         <% if (OutParams.Count > 0) { %>
  1675.         <span class="label">Output Parameters</span>
  1676.             <div class="smallSeparator"></div>
  1677.             <table class="paramTable" cellspacing="1" cellpadding="5">
  1678.             <asp:repeater id="OutputParamsRepeater" runat=server>
  1679.                 <itemtemplate>
  1680.                     <tr>
  1681.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  1682.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  1683.                     </tr>
  1684.                 </itemtemplate>
  1685.             </asp:repeater>
  1686.             </table>
  1687.         <br>
  1688.         <% } %>
  1689.         
  1690.         <span class="label">Remarks</span>
  1691.         <div class="smallSeparator"></div>
  1692.         <%=OperationDocumentation%>
  1693.         <br><br>
  1694.         <span class="label">Technical information</span>
  1695.         <div class="smallSeparator"></div>
  1696.         Format: <%=CurrentOperationFormat%>
  1697.         <br>Supported protocols: <%=CurrentOperationProtocols%>
  1698.     <% } %>
  1699.     
  1700. <!--
  1701.     **********************************************************
  1702.     Operation description - Test form
  1703. -->
  1704.  
  1705.     <% if (CurrentTab == "test") { 
  1706.         if (CurrentOperationSupportsTest) {%>
  1707.             Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
  1708.             <form action="<%=PageName%>" method="GET">
  1709.             <input type="hidden" name="page" value="<%=CurrentPage%>">
  1710.             <input type="hidden" name="tab" value="<%=CurrentTab%>">
  1711.             <input type="hidden" name="op" value="<%=CurrentOperationName%>">
  1712.             <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
  1713.             <input type="hidden" name="ext" value="testform">
  1714.             <table class="paramFormTable" cellspacing="0" cellpadding="3">
  1715.             <asp:repeater id="InputFormParamsRepeater" runat=server>
  1716.                 <itemtemplate>
  1717.                     <tr>
  1718.                     <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
  1719.                     <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
  1720.                     </tr>
  1721.                 </itemtemplate>
  1722.             </asp:repeater>
  1723.             <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
  1724.             </table>
  1725.             </form>
  1726.             <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
  1727.             The web service returned the following result:<br/><br/>
  1728.             <div class="codePanel"><%=GetTestResult()%></div>
  1729.             </div>
  1730.         <% } else {%>
  1731.         The test form is not available for this operation because it has parameters with a complex structure.
  1732.         <% } %>
  1733.     <% } %>
  1734.     
  1735. <!--
  1736.     **********************************************************
  1737.     Operation description - Message Layout
  1738. -->
  1739.  
  1740.     <% if (CurrentTab == "msg") { %>
  1741.         
  1742.         The following are sample SOAP requests and responses for each protocol supported by this method:
  1743.             <br/><br/>
  1744.         
  1745.         <% if (IsOperationSupported ("Soap")) { %>
  1746.             <span class="label">Soap</span>
  1747.             <br/><br/>
  1748.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
  1749.             <br/>
  1750.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
  1751.             <br/>
  1752.         <% } %>
  1753.         <% if (IsOperationSupported ("HttpGet")) { %>
  1754.             <span class="label">HTTP Get</span>
  1755.             <br/><br/>
  1756.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
  1757.             <br/>
  1758.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
  1759.             <br/>
  1760.         <% } %>
  1761.         <% if (IsOperationSupported ("HttpPost")) { %>
  1762.             <span class="label">HTTP Post</span>
  1763.             <br/><br/>
  1764.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
  1765.             <br/>
  1766.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
  1767.             <br/>
  1768.         <% } %>
  1769.         
  1770.     <% } %>
  1771. <%} else if (CurrentPage == "proxy") {%>
  1772. <!--
  1773.     **********************************************************
  1774.     Client Proxy
  1775. -->
  1776.     <form action="<%=PageName%>" name="langForm" method="GET">
  1777.         Select the language for which you want to generate a proxy 
  1778.         <input type="hidden" name="page" value="<%=CurrentPage%>"> 
  1779.         <SELECT name="lang" onchange="langForm.submit()">
  1780.             <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
  1781.             <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
  1782.         </SELECT>
  1783.           
  1784.     </form>
  1785.     <br>
  1786.     <span class="label"><%=CurrentProxytName%></span>   
  1787.     <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
  1788.     <br><br>
  1789.     <div class="codePanel">
  1790.     <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
  1791.     </div>
  1792. <%} else if (CurrentPage == "wsdl") {%>
  1793. <!--
  1794.     **********************************************************
  1795.     Service description
  1796. -->
  1797.     <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
  1798.     The description of this web service is composed by several documents. Click on the document you want to see:
  1799.     
  1800.     <ul>
  1801.     <% 
  1802.         for (int n=0; n<descriptions.Count; n++)
  1803.             Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
  1804.         for (int n=0; n<schemas.Count; n++)
  1805.             Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
  1806.     %>
  1807.     </ul>
  1808.     
  1809.     <%} else {%>
  1810.     <%}%>
  1811.     <br>
  1812.     <span class="label"><%=CurrentDocumentName%></span>   
  1813.     <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
  1814.     <br><br>
  1815.     <div class="codePanel">
  1816.     <div class="code-xml"><%=GenerateDocument ()%></div>
  1817.     </div>
  1818.  
  1819. <%}%>
  1820.  
  1821. <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  1822. </td>
  1823. <td width="20px"></td>
  1824. </tr>
  1825.  
  1826. </table>
  1827. </body>
  1828. </html>
  1829.